package com.wsx.sky.sentinel.api;

import com.wsx.sky.sentinel.fisrt.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author wangshuaixin
 * @Title: com.wsx.sky.sentinel.api.UserController
 * @Description: TODO
 * @date 2019/03/06
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private UserService userService = new UserService();


    @RequestMapping(
            value = "/get/v1/{uid}",
            method = {RequestMethod.GET}
    )
    public UserService.User getUser(@PathVariable("uid") long uid, HttpServletResponse response) {
        UserService.User user = userService.getUser(uid);
        if (null == user) {
            response.setStatus(501);
            return new UserService.User("限流", -1);
        }
        return user;
    }


    private com.wsx.sky.sentinel.second.UserService userServiceV2 = new com.wsx.sky.sentinel.second.UserService();
    @RequestMapping(
            value = "/get/v2/{uid}",
            method = {RequestMethod.GET}
    )
    public UserService.User getUserV2(@PathVariable("uid") long uid, HttpServletResponse response) {
        UserService.User user = userServiceV2.getUser(uid);
        if (null == user) {
            response.setStatus(501);
            return new UserService.User("限流", -1);
        }
        return user;
    }

    private com.wsx.sky.sentinel.third.UserService userServiceV3 = new com.wsx.sky.sentinel.third.UserService();
    @RequestMapping(
            value = "/get/v3/{uid}",
            method = {RequestMethod.GET}
    )
    public UserService.User getUserV3(@PathVariable("uid") long uid, HttpServletResponse response) {
        UserService.User user = userServiceV3.getUser(uid);
        if (null == user) {
            response.setStatus(501);
            return new UserService.User("限流", -1);
        }
        return user;
    }
}
